<template>
  <!--    请确认您所报名的机构名称：XXX  -->
  <div class="registerFormDiv">
    <el-form
        label-position="top"
        :rules="rules"
        ref="registerForm"
        :model="registerForm"
        label-width="80px"
    >
      <div>
        <div>
          <el-form-item :required="true" :label="!orgLock ? '机构代码（ 提示：请填写机构代码并确认培训机构 ）':`机构代码（ 提示：*您选择的报读的机构名称为【${org_name}】）`" label-width="400px">
            <div style="display: flex">
              <el-input
                  size="small"
                  style="width: 160px"
                  :disabled="orgLock"
                  v-model="registerForm.org_code"
              ></el-input>
              <div>
                <el-button
                    v-if="!orgLock"
                    size="small"
                    :disabled="orgLock"
                    style="margin-left: 20px"
                    @click="getOrg"
                >确定</el-button
                >
              </div>
            </div>
          </el-form-item>
        </div>
      </div>
      <div v-show="course_isShow">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="course_id" label="报读的科目（级别）">
              <el-select
                  size="small"
                  v-model="registerForm.course_id"
                  placeholder="请选择报读的科目（级别）"
              >
                <el-option
                    v-for="item in courseList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
                v-if="course_name.includes('薪酬管理')"
                prop="exam_city"
                label="预计考点城市"
            >
              <el-select
                  size="small"
                  v-model="registerForm.exam_city"
                  placeholder="请选择考点城市"
              >
                <el-option
                    v-for="item in exam_cityOptions"
                    :key="item.id"
                    :label="item.exam_city"
                    :value="item.exam_city"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="name" label="学员姓名">
              <el-input
                  size="small"
                  :disabled="true"
                  v-model="registerForm.name"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item :required="true" label="性别">
              <el-radio-group
                  :disabled="true"
                  v-model="registerForm.gender"
              >
                <el-radio :label="'m'">男</el-radio>
                <el-radio :label="'f'">女</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="last_py" label="姓拼音">
              <el-input
                  onblur="this.value=this.value.toUpperCase()"
                  size="small"
                  v-model="registerForm.last_py"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="first_py" label="名拼音">
              <el-input
                  onblur="this.value=this.value.toUpperCase()"
                  size="small"
                  v-model="registerForm.first_py"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="card_type" label="证件类型">
              <el-select
                  size="small"
                  :disabled="true"
                  v-model="registerForm.card_type"
                  placeholder="请选择证件类型"
              >
                <el-option
                    v-for="item in cardOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="card_id" label="证件号码">
              <el-input
                  style="width: 200px; margin-right: 20px"
                  size="small"
                  :disabled="true"
                  v-model="registerForm.card_id"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="birthday" label="出生日期">
              <el-date-picker
                  style="width: auto"
                  size="small"
                  :disabled="true"
                  format="yyyy 年 MM 月 dd 日"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                  v-model="registerForm.birthday"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item prop="com_name" label="单位名称">
              <el-input
                  size="small"
                  v-model="registerForm.com_name"
                  placeholder="没有工作填写 “无” "
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="20">
            <el-form-item prop="province" label="工作区域">
              <el-cascader
                  style="width: 100%!important;"
                  size="small"
                  :options="areaOptions"
                  v-model="selectedOptions"
                  @change="addressChange"
              >
              </el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="hig_edu" label="最高学历">
              <el-select
                  size="small"
                  v-model="registerForm.hig_edu"
                  placeholder="最高学历"
                  @change="changeHig_edu"
              >
                <el-option label="研究生及以上" value="研究生及以上"></el-option>
                <el-option label="本科" value="本科"></el-option>
                <el-option label="专科" value="专科"></el-option>
                <el-option label="其他" value="其他"></el-option>
                <el-option label="研究生及以上（在读）" value="研究生及以上（在读）"></el-option>
                <el-option label="本科（在读）" value="本科（在读）"></el-option>
                <el-option label="专科（在读）" value="专科（在读）"></el-option>
                <el-option label="其他（在读）" value="其他（在读）"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-if="IsReadHig_edu" :span="8">
            <el-form-item  prop="grad_time" label="毕业年份">
              <el-date-picker
                  size="small"
                  type="month"
                  format="yyyy 年 MM 月"
                  value-format="yyyy-MM-DD"
                  placeholder="选择日期"
                  v-model="registerForm.grad_time"
                  style="width: 160px"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="major" label="相关专业">
              <el-select
                  size="small"
                  v-model="registerForm.major"
                  placeholder="相关专业"

              >
                <el-option label="人力资源管理" value="人力资源管理"></el-option>
                <el-option label="工商管理" value="工商管理"></el-option>
                <el-option label="行政管理" value="行政管理"></el-option>
                <el-option label="会计" value="会计"></el-option>
                <el-option label="财政、税务" value="财政、税务"></el-option>
                <el-option label="财政管理" value="财政管理"></el-option>
                <el-option label="其他" value="其他"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item :required="true" label="相关资质或证书">
              <el-select
                  size="small"
                  style="width: 420px;"
                  v-model="registerForm.cert"
                  placeholder="请选择"
              >
                <el-option
                    v-for="item in certDisplayOptions"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="ind_type" label="行业类型">
              <el-select
                  size="small"
                  v-model="registerForm.ind_type"
                  placeholder="请选择行业类型"
              >
                <el-option
                    v-for="item in ind_typeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item prop="com_type" label="单位类型">
              <el-select
                  style="width: 420px; margin-right: 20px"
                  size="small"
                  v-model="registerForm.com_type"
                  placeholder="请选择单位类型"
              >
                <el-option
                    v-for="item in com_typeList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="email" label="电子邮箱">
              <el-input
                  size="small"
                  v-model="registerForm.email"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item prop="work_duty" label="职务">
              <el-select
                  style="width: 420px"
                  size="small"
                  v-model="registerForm.work_duty"
                  placeholder="请选择职务"
              >
                <el-option
                    v-for="item in work_dutyList"
                    :key="item.value"
                    :label="item.name"
                    :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20"><el-col :span="16">
          <el-form-item prop="work_age" label-width="auto" label="从事薪酬管理（含薪税服务）工作年限（含实习经历）">

            <el-input
                oninput="value=value.replace(/[^0-9.]/g,'')"
                size="small"
                type="number"
                v-model="registerForm.work_age"
                style="width:100px"
            ></el-input>

          </el-form-item></el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="8">
            <el-form-item prop="phone" label="手机号码">
              <el-input
                  size="small"
                  :disabled="true"
                  v-model="registerForm.phone"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item prop="code" label="短信验证码">
              <div style="display: flex; align-items: center">
                <el-input
                    style="width: 120px"
                    size="small"
                    v-model="registerForm.code"
                ></el-input>
                <div>
                  <el-button
                      :disabled="isDisabled"
                      size="small"
                      style="font-size: unset; margin-left: 10px"
                      @click="codeHandle"
                  >
                    <tencent-captcha
                        ref="captcha"
                        :phone="registerForm.phone"
                        scene="1"
                    ></tencent-captcha>
                  </el-button>
                </div>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-checkbox style="padding: 20px 0" size="small" v-model="isRegister"><span style="font-size: 12px;"
            >本人承诺在申请国际薪税师报名时所提供的个人信息及材料真实、合法、有效，否则将承担一切责任及后果。</span></el-checkbox>
          </el-col>
        </el-row>
        <el-row>
          <el-col>
            <el-form-item>
              <el-button
                  size="small"
                  type="primary"
                  @click="submitForm('registerForm')"
              >提交</el-button
              >
              <!--              <el-button v-if="isNotFirstRegister == false" size="small" @click="resetForm">重置</el-button>-->
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>
  </div>
</template>

<script>
import Pinyin from "js-pinyin";
import { changeName } from "../../utils/changName";
import TencentCaptcha from "../../components/TencentCaptcha/TencentCaptcha";
import { getOrg } from "../../request/api";
import {
  regionData,
  CodeToText,
  TextToCode,
} from "element-china-area-data";
import registerForm from "../../views/mobile/user/components/registerForm";

export default {
  name: "registerForm",
  props: {
    userMessage: {
      type: Object,
      default: null,
    },
    registerParams: {
      type: Array,
      default: [],
    },
    isNotFirstRegister: {
      type: Boolean,
      default: false,
    },
    isShow: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    var card_id_rule = (rule, value, callback) => {
      if (this.registerForm.card_type == 1) {
        let reg =
            /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
        if (value === "") {
          callback(new Error("请填写身份证号码"));
        } else if (!reg.test(value)) {
          callback(new Error("身份证格式错误"));
        } else {
          let birthday = this.registerForm.card_id.substring(6, 14);
          this.registerForm.birthday =
              birthday.slice(0, 4) +
              "-" +
              birthday.slice(4, 6) +
              "-" +
              birthday.slice(6);
          callback();
        }
      } else if (this.registerForm.card_type == 2) {
        let reg = /^[A-Z,a-z,\d]+$/;
        if (value === "") {
          callback(new Error("请填写护照"));
        } else if (!reg.test(value)) {
          callback(new Error("护照格式错误"));
        } else {
          callback();
        }
      } else if (this.registerForm.card_type == 3) {
        let reg = /^[A-Z,a-z,\d]+$/;
        if (value === "") {
          callback(new Error("请填写港澳台胞证"));
        } else if (!reg.test(value)) {
          callback(new Error("证件格式错误"));
        } else {
          callback();
        }
      } else {
        callback();
      }
    };
    var phone_rule = (rule, value, callback) => {
      let phoneRule = /^1[23456789]\d{9}$/;
      if (value === "") {
        callback(new Error("请输入手机号码"));
      } else if (!phoneRule.test(value)) {
        callback(new Error("手机号码格式错误"));
      } else {
        callback();
      }
    };
    var email_rule = (rule, value, callback) => {
      let reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
      if (value === "") {
        callback(new Error("请填写电子邮箱"));
      } else if (!reg.test(value)) {
        callback(new Error("电子邮箱格式错误"));
      } else {
        callback();
      }
    };
    var province_rule = (rule, value, callback) => {
      console.log('工作区域参数',value);
      if (this.registerForm.province === "" || this.registerForm.province == null) {
        callback(new Error("请选择省份"));
      } else {
        callback();
      }
    };
    var last_py_rule = (rule, value, callback) => {
      let reg = /^[A-Z,a-z]+$/;
      if (value === "") {
        callback(new Error("请填写姓拼音"));
      } else if (!reg.test(value)) {
        callback(new Error("格式错误"));
      } else {
        callback();
      }
    };
    var first_py_rule = (rule, value, callback) => {
      let reg = /^[A-Z,a-z]+$/;
      if (value == "") {
        callback(new Error("请填写名拼音"));
      } else if (!reg.test(value)) {
        callback(new Error("格式错误"));
      } else {
        callback();
      }
    };
    var work_duty = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请填写职务"));
      } else {
        callback();
      }
    };
    var hig_edu = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请选择最高学历"));
      } else {
        callback();
      }
    };
    return {
      IsReadHig_edu:true,
      org_name:'',
      isRegisterSpan:'（ 提示：请填写机构代码并确认培训机构 ）',
      isDisabled:false,
      course: null,
      flag: false, //是否满足报考条件
      certDisplayOptions: [
        {id:1,name:'ACCA职业资格证书'},
        {id:2,name:'AICPA职业资格证书'},
        {id:3,name:'ATHE国际薪税师能力水平评价证书二级（中级）'},
        {id:4,name:'ATHE国际薪税师能力水平评价证书三级（初级）'},
        {id:5,name:'CIMA职业资格证书'},
        {id:6,name:'CMA职业资格证书'},
        {id:7,name:'IFA职业资格证书'},
        {id:8,name:'IFA国际薪税师能力水平评价证书二级（中级）'},
        {id:9,name:'IFA国际薪税师能力水平评价证书三级（初级）'},
        {id:10,name:'初级会计师职称证书'},
        {id:11,name:'初级经济师职称证书'},
        {id:12,name:'法律职业资格证书'},
        {id:13,name:'高级会计师职称证书'},
        {id:14,name:'高级经济师职称证书'},
        {id:15,name:'企业人力资源管理师职业技能（一级）证书'},
        {id:16,name:'企业人力资源管理师职业技能（二级）证书'},
        {id:17,name:'企业人力资源管理师职业技能（三级）证书'},
        {id:18,name:'企业人力资源管理师职业技能（四级）证书'},
        {id:19,name:'企业人力资源管理师职业资格（一级）证书'},
        {id:20,name:'企业人力资源管理师职业资格（二级）证书'},
        {id:21,name:'企业人力资源管理师职业资格（三级）证书'},
        {id:22,name:'企业人力资源管理师职业资格（四级）证书'},
        {id:23,name:'税务师职业资格证书'},
        {id:24,name:'薪酬管理职业技能（初级）证书'},
        {id:25,name:'薪酬管理职业技能（中级）证书'},
        {id:26,name:'薪酬管理职业技能（高级）证书'},
        {id:27,name:'薪税师职业技能（一级）证书'},
        {id:28,name:'薪税师职业技能（二级）证书'},
        {id:29,name:'薪税师职业技能（三级）证书'},
        {id:30,name:'薪税师职业技能（四级）证书'},
        {id:31,name:'中国商业联合会薪税师能力水平评价证书二级（中级）'},
        {id:32,name:'中国商业联合会薪税师能力水平评价证书三级（初级）'},
        {id:33,name:'中级会计师职称证书'},
        {id:34,name:'中级经济师职称证书'},
        {id:35,name:'注册会计师职业资格证书'},
        {id:0,name:'无'}
      ],
      work_dutyList: [
        {
          name: "单位负责人/高级管理人员（董事长/总裁/副总裁等）",
          value:
              "单位负责人/高级管理人员（董事长/总裁/副总裁等）#Person in charge / Senior Management (Chairman / President / Vice President, etc.)",
        },
        {
          name: "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）",
          value:
              "事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）#Head of the firm / Senior Management (Chairman / Equity Partners / Salaried Partners, etc.)",
        },
        {
          name: "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）",
          value:
              "人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）#Human Resources Dept. (Payments Director Post and above/Payments and Tax Service Director Post and above)",
        },
        {
          name: "财务部（总监岗及以上）",
          value:
              "财务部（总监岗及以上）#Finance Dept. (Director Post and above)",
        },
        {
          name: "客服部/市场部（总监岗及以上）",
          value:
              "客服部/市场部（总监岗及以上）#Customer Service Dept. / Marketing Dept. (Director Post and above)",
        },
        {
          name: "业务部（总监岗及以上）",
          value:
              "业务部（总监岗及以上）#Business Dept. (Director Post and above)",
        },
        {
          name: "其他未列明部门（总监岗及以上）",
          value:
              "其他未列明部门（总监岗及以上）#Other Unspecified Departments (Director Post and above)",
        },
        {
          name: "人力资源部（薪酬经理岗/薪税服务经理岗）",
          value:
              "人力资源部（薪酬经理岗/薪税服务经理岗）#Human Resources Dept. (Payments Manager Post/Payments and Tax Service Manager Post)",
        },
        {
          name: "财务部（经理岗）",
          value:
              "财务部（经理岗）#Finance Dept. (Manager Post)",
        },
        {
          name: "客服部/市场部（经理岗）",
          value:
              "客服部/市场部（经理岗）#Customer Service Dept. / Marketing Dept.  (Manager Post)",
        },
        {
          name: "业务部（经理岗）",
          value:
              "业务部（经理岗）#Business Dept. (Manager Post)",
        },
        {
          name: "其他未列明部门（经理岗）",
          value:
              "其他未列明部门（经理岗）#Other Unspecified Departments (Manager Post)",
        },
        {
          name: "人力资源部（薪酬专员岗/薪税服务专员岗）",
          value:
              "人力资源部（薪酬专员岗/薪税服务专员岗）#Human Resources Dept. (Payments Specialist Post/Payments and Tax Service Specialist Post)",
        },
        {
          name: "财务部（专员岗）",
          value:
              "财务部（专员岗）#Finance Dept. (Specialist Post)",
        },
        {
          name: "客服部/市场部（专员岗)",
          value:
              "客服部/市场部（专员岗）#Customer Service Dept. / Marketing Dept.  (Specialist Post)",
        },
        {
          name: "业务部（专员岗）",
          value:
              "业务部（专员岗）#Business Dept. (Specialist Post)",
        },
        {
          name: "其他未列明部门（专员岗）",
          value:
              "其他未列明部门（专员岗）#Other Unspecified Departments (Specialist Post)",
        },
        {
          name: "其他人员（在校学生-人力资源管理、工商管理、行政管理专业）",
          value:
              " 其他人员（在校学生-人力资源管理、工商管理、行政管理专业）#Others (Student-Major in HR Management, Business Administration, Administration）",
        },
        {
          name: "其他人员（在校学生-会计、税务、财务管理专业）",
          value:
              "其他人员（在校学生-会计、税务、财务管理专业）#Others (Student-Major in Accounting, Taxation, Financial management）",
        },
        {
          name: "其他人员（在校学生-其他专业）",
          value:
              "其他人员（在校学生-其他专业）#Others (Student-other majors）",
        },
        {
          name: "自由职业者",
          value:
              "自由职业者#Freelancers",
        }
      ],
      ind_typeList: [
        {value:1,name:'人力资源与人力资本服务'},
        {value:2,name:'集成电路'},
        {value:3,name:'人工智能'},
        {value:4,name:'软件与平台'},
        {value:5,name:'生命科学'},
        {value:6,name:'生物医药'},
        {value:7,name:'医疗保健'},
        {value:8,name:'航空与航天'},
        {value:9,name:'汽车'},
        {value:10,name:'化工'},
        {value:11,name:'工业产品和服务'},
        {value:12,name:'消费品'},
        {value:13,name:'能源和自然资源'},
        {value:14,name:'金融'},
        {value:15,name:'基础建设和建筑产品'},
        {value:16,name:'机械和设备'},
        {value:17,name:'媒体'},
        {value:18,name:'金属和矿业'},
        {value:19,name:'私募基金'},
        {value:20,name:'零售'},
        {value:21,name:'高科技'},
        {value:22,name:'电信'},
        {value:23,name:'公用事业'},
        {value:24,name:'教育'},
        {value:25,name:'文化'},
        {value:26,name:'其他'},
        {value:27,name:'无'}
      ],
      com_typeList: [
        {value:1,name:'企事业单位'},
        {value:2,name:'人力资源服务机构'},
        {value:3,name:'会计（税务、律师）事务所'},
        {value:4,name:'金融机构（银行、证券、保险、 信托、基金等）'},
        {value:5,name:'其他中介机构'},
        {value:6,name:'院校'},
        {value:7,name:'其他'}
      ],
      isRegister: false, //确认阅读注册协议
      course_isShow: false,
      orgLock: false, //是否禁用机构输入框
      courseList: [], //科目集合
      areaOptions: regionData, //省市区三级联动
      selectedOptions: [], //选择后的省市区对象数组
      //预计考点城市
      exam_cityOptions: [],
      cardOptions: [
        { id: 1, name: "居民身份证" },
        { id: 2, name: "护照" },
        { id: 3, name: "港澳台胞身份证" },
      ],
      sex: { 1: "m", 2: "f" },
      registerForm: {
        cert: 0, //资质证书
        org_code: "", //机构
        course_id: "", //科目
        name: "", //学员姓名 --潘童
        last_py: "", //姓拼音
        first_py: "", //名拼音
        gender: "m", //性别
        card_type: 1, //证件类型
        birthday: "", //出生日期
        card_id: "", //证件号码 --320723199807023528
        phone: "", //手机号码 --18360556606
        email: "", //电子邮箱 --181501830@qq.com
        code: "",
        major:"",//相关专业
        hig_edu: "", //最高学历
        grad_time: "", //毕业时间
        province: "", //省份 --江苏省
        city: "", //城市 --南京市
        dis:"",//区 -- 万载县
        address: "", //居住地
        exam_city: "", //预计考点城市
        com_name: "", //单位名称 --爱柔则有限公司
        work_duty: "", //现有职务 --总经理助理
        buy_book: false, //是否购书
        sign: "", //电子签名
        agree: false, //是否同意培训合同
        work_age: 0, //工作年限
        ind_type:"", // 行业类型
        com_type:"" //单位类型
      },
      //电子签名参数-----------
      // lineWidth: 6,
      // lineColor: '#000000',
      // bgColor: '',
      // resultImg: '',
      // isCrop: false,
      rules: {
        work_age: [
          { required: true, message: "请填写从业年限", trigger: "blur" },
        ],
        major:[
          {required: true, message: "请填写相关专业", trigger: "change"}
        ],
        grad_time: [
          { required: true, message: "请选择毕业年份", trigger: "change" },
        ],
        org_code: [
          { required: true, message: "请输入机构代码", trigger: "blur" },
        ],
        course_id: [
          { required: true, message: "请选择报读的科目（级别）", trigger: "change" },
        ],
        name: [{ required: true, message: "请输入姓名", trigger: "blur" }],
        last_py: [{ required: true, validator: last_py_rule, trigger: "blur" }],
        first_py: [
          { required: true, validator: first_py_rule, trigger: "blur" },
        ],
        card_type: [
          { required: true, message: "请选择证件类型", trigger: "blur" },
        ],
        card_id: [{ required: true, validator: card_id_rule, trigger: "blur" }],
        birthday: [
          { required: true, message: "请选择出生日期", trigger: "change" },
        ],
        phone: [
          {
            required: true,
            validator: phone_rule,
            trigger: ["blur", "change"],
          },
        ],
        email: [{ required: true, validator: email_rule, trigger: "blur" }],
        code: [{ required: true, message: "验证码不能为空", trigger: "blur" }],
        province: [
          { required: true, validator: province_rule, trigger: "change" },
        ],
        address: [{ required: true, message: "请输入居住地", trigger: "blur" }],
        exam_city: [
          { required: true, message: "请选择考点城市", trigger: "change" },
        ],
        com_name: [
          { required: true, message: "请填写单位名称", trigger: "blur" },
        ],
        work_duty: [{ required: true, validator: work_duty, trigger: "change" }],
        ind_type: [{ required: true, message:"请选择行业类型", trigger: "change" }],
        com_type: [{ required: true, message:"请选择单位类型", trigger: "change" }],
        buy_book: [
          { required: true, message: "请选择是否购买证书", trigger: "change" },
        ],
        hig_edu: [
          { required: true, validator: hig_edu, trigger: "change" },
        ],
      },
      value: "",
    };
  },
  created() {
    console.log("培训表单用户信息", this.userMessage);
    if (this.userMessage) {
      this.registerForm.phone = this.userMessage.person.mobile;
      this.registerForm.name = this.userMessage.person.personName;
      this.registerForm.card_id = this.userMessage.person.idCard;
      console.log("性别", this.sex[this.userMessage.person.sex]);
      this.registerForm.gender = this.sex[this.userMessage.person.sex];
      this.registerForm.address = this.userMessage.person.address;
      // let {lastname,firstname} = changeName(this.registerForm.name);
      // console.log('changeName',lastname,firstname);
      // console.log(Pinyin.getFullChars(lastname));
      // this.registerForm.last_py = Pinyin.getFullChars(lastname);
      // this.registerForm.first_py = Pinyin.getFullChars(firstname);
      // let reg = /.+?(省|市|自治区|自治州|县|区)/g;
      // console.log("省份", this.registerForm.address.match(reg));
      // let areaArray = this.registerForm.address.match(reg);
      // this.registerForm.province = areaArray[0];
      // this.registerForm.city = areaArray[1];
      // this.registerForm.dis = areaArray[2];
      // let cityCode = "";
      // try {
      //   if (this.registerForm.province == this.registerForm.city) {
      //     cityCode = TextToCode[this.registerForm.province]["市辖区"].code;
      //   } else {
      //     cityCode =
      //       TextToCode[this.registerForm.province][this.registerForm.city].code;
      //   }
      //   this.selectedOptions.push(
      //     TextToCode[this.registerForm.province].code,
      //     cityCode,
      //     TextToCode[this.registerForm.province][this.registerForm.city][this.registerForm.dis].code
      //   );
      // } catch {}
      // console.log(
      //   "城市Code",
      //   TextToCode[this.registerForm.province].code,
      //   cityCode,
      //   TextToCode[this.registerForm.province][this.registerForm.city][this.registerForm.dis].code
      // );
      this.registerForm.birthday =
          this.registerForm.card_id.substring(6, 14).slice(0, 4) +
          "-" +
          this.registerForm.card_id.substring(6, 14).slice(4, 6) +
          "-" +
          this.registerForm.card_id.substring(6, 14).slice(6);
    }
    if (this.registerParams.length > 0) {
      console.log('this.registerParams',this.registerParams);
      console.log(
          "所在城市",
          this.registerParams[0].province,
          this.registerParams[0].city,
          this.registerParams[0].dis
      );
      let cityCode = "";
      if (this.registerParams[0].province == this.registerParams[0].city) {
        // console.log("123");
        // cityCode = TextToCode[this.registerParams[0].province]["市辖区"].code;
        try {
          this.selectedOptions.push(
              TextToCode[this.registerParams[0].province].code,
              TextToCode[this.registerParams[0].province]["市辖区"].code,
              TextToCode[this.registerParams[0].province]['市辖区'][this.registerParams[0].dis].code
          );
        } catch (error) {
          console.log(error);
        }
      } else {
        try {
          this.selectedOptions.push(
              TextToCode[this.registerParams[0].province].code,
              TextToCode[this.registerParams[0].province][this.registerParams[0].city].code,
              TextToCode[this.registerParams[0].province][this.registerParams[0].city][this.registerParams[0].dis].code
          );
        } catch (error) {
          console.log(error)
        }
      }
      // try {
      //   console.log(TextToCode[this.registerParams[0].province].code,
      //   cityCode,
      //   TextToCode[this.registerParams[0].province]['市辖区'][this.registerParams[0].dis].code
      //   )
      // } catch (error) {
      //   console.log(error)
      // }
      for (let item in this.registerForm) {
        // this.registerParams[this.registerParams.length - 1]["exam_city"] = "";
        this.registerForm[item] =
            this.registerParams[this.registerParams.length - 1][item];
        if(this.registerForm['province'] == null || this.registerForm['city'] == null || this.registerForm['dis'] == null){
          this.registerForm['province'] = "";
          this.registerForm['city'] = "";
          this.registerForm['dis'] = "";
        }
      }
      if(this.registerForm.hig_edu.includes('在读')){
        this.IsReadHig_edu = false;
        this.registerForm.grad_time = null;
      }
      // this.resetForm('registerForm');
      console.log("this.registerForm", this.registerForm);
    }
  },
  watch:{
    'registerForm.hig_edu':{
      handler(){
        if(this.registerForm.hig_edu.includes('在读')){
          this.registerForm.grad_time = null;
        }
      }
    }
  },
  methods: {
    changeHig_edu(){
      console.log('this.registerForm.hig_edu',this.registerForm.hig_edu)
      if(this.registerForm.hig_edu.includes('在读')){
        this.IsReadHig_edu = false;
      }else{
        this.IsReadHig_edu = true;
      }
    },
    isRegisterFun(){
      window.open('/train_register.html')
    },
    isPrivacyFun(){
      window.open('/train_privacy.html')
    },
    //创建方法er
    DateDiffer(Date_end) {
      //date1结束时间
      let date1 = new Date(Date_end);
      //date2当前时间
      let date2 = new Date();
      date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
      date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
      const diff = date2.getTime() - date1.getTime(); //当前时间减去毕业时间
      const diffDate = diff / (24 * 60 * 60 * 1000 * 365); //计算当前时间与结束时间之间相差天数
      console.log("毕业天数", diffDate);
      return diffDate;
    },
    codeHandle() {
      if(this.$refs.isShow){
        this.$refs.captcha.handleCode();
        this.isDisabled = true
      }
    },
    getCode(e) {
      console.log("获取验证码", e);
    },
    //重置签名
    handleReset() {
      this.$refs.esign.reset();
    },
    //查询机构
    getOrg() {
      getOrg(this.registerForm.org_code)
          .then((res) => {
            let _this = this;
            console.log("机构代码", res);
            this.course = res.course;
            let orgName = res.org_name;
            this.org_name = res.org_name;
            this.$confirm(`*您选择报读的培训机构为：【${orgName}】`, "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
                .then(() => {
                  this.$message({
                    type: "success",
                    message: "已提交",
                  });
                  _this.orgLock = true;
                  _this.courseList = res.course;
                  _this.course_isShow = true;
                })
                .catch(() => {
                  this.$message({
                    type: "info",
                    message: "已取消",
                  });
                });
          })
          .catch((err) => {
            this.$message({
              type: "error",
              message: err.msg,
            });
          });
    },
    //获取省市区
    addressChange(arr) {
      console.log("省市区", arr);
      console.log(CodeToText[arr[0]], CodeToText[arr[1]]);
      this.registerForm.province = CodeToText[arr[0]];
      this.registerForm.city = CodeToText[arr[1]];
      this.registerForm.dis = CodeToText[arr[2]];
    },
    //提交
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.isRegister) {
            this.flagFunction();
            if (this.flag) {
              this.registerForm.transaction_id =
                  this.$cookies.get("transactionNo");
              console.log(this.registerForm.last_py.toUpperCase(),this.registerForm.first_py.toUpperCase())
              this.registerForm.first_py = this.registerForm.first_py.toUpperCase();
              this.registerForm.last_py = this.registerForm.last_py.toUpperCase();
              this.registerForm.work_age = Number(this.registerForm.work_age);
              console.log("表单信息", this.registerForm);
              this.$emit("registerForm", this.registerForm);
              this.$refs["captcha"].isShow = this.isShow;
            } else {
              this.$message({
                message: "对不起,您暂未满足报考条件",
                type: "error",
              });
            }
          } else {
            this.$message({
              message: "请阅读并确认所提供的个人信息及材料真实、有效、合法。",
              type: "warning",
            });
            return false;
          }
        } else {
          this.$message({
            type: "warning",
            message: "请检查是否漏填字段",
          });
          return false;
        }
      });
      // this.$refs[formName].validate((valid) => {
      //   if (valid) {
      //     this.$refs.esign
      //       .generate()
      //       .then((res) => {
      //         if (this.checked) {
      //           this.flagFunction();
      //           if(this.flag){
      //             this.registerForm.sign = res;
      //             this.registerForm.transaction_id =
      //             this.$cookies.get("transactionNo");
      //             console.log("表单信息", this.registerForm);
      //             this.$emit("registerForm", this.registerForm);
      //             this.$refs["captcha"].isShow = this.isShow;
      //           }else{
      //             this.$message({
      //             message: "对不起,您暂未满足报考条件",
      //             type: "error",
      //           });
      //           }
      //         } else {
      //           this.$message({
      //             message: "请同意培训合同内容并确认个人信息安全保护条款",
      //             type: "warning",
      //           });
      //           return false;
      //         }
      //       })
      //       .catch((err) => {
      //         this.$message({
      //           message: "请填写电子签名",
      //           type: "warning",
      //         });
      //         return false;
      //       });
      //   } else {
      //     this.$message({
      //       type: "warning",
      //       message: "请检查是否漏填字段",
      //     });
      //     return false;
      //   }
      // });
    },
    //重置
    resetForm() {
      // this.flagFunction();
      this.orgLock = false;
      this.courseList = [];
      // this.handleReset();
      this.$refs["registerForm"].resetFields();
    },
    //条件判断
    flagFunction() {
      console.log(
          "国际薪税师等级",
          this.course.filter((item) => item.id == this.registerForm.course_id)[0]
      );
      if (
          this.course.filter((item) => item.id == this.registerForm.course_id)[0]
              .name == "国际薪税师一级（高级）"
      ) {
        switch (this.registerForm.hig_edu) {
          case "研究生及以上":
            this.flag =
                this.registerForm.work_age >= 3 ? true : false;
            console.log("修改后Flag", this.flag);
            break;
          case "本科":
            this.flag =
                this.registerForm.work_age >= 5 ? true : false;
            break;
          case "专科":
            this.flag =
                this.registerForm.work_age >= 10 ? true : false;
            break;
        }
        for (let item of this.certDisplayOptions) {
          switch (item.id) {
            case 26:
            case 27:
            case 19:
            case 15:
            case 23:
            case 35:
            case 13:
            case 14:
            case 12:
            case 1:
            case 2:
            case 7:
              this.$set(item, "flag", 3);
              break;
            case 3:
            case 8:
            case 31:
            case 25:
            case 28:
            case 20:
            case 16:
            case 33:
            case 34:
            case 6:
            case 5:
              this.$set(item,'flag',5);
              break;
          }
        }
        for (let item of this.certDisplayOptions) {
          if (item.id == this.registerForm.cert) {
            console.log('一级item',item)
            console.log(this.registerForm.work_age,item.flag)
            if (this.registerForm.work_age >= item.flag) {

              this.flag = true;
            }
          }
        }
        for (let item of this.work_dutyList) {
          switch (item.name) {
            case '单位负责人/高级管理人员（董事长/总裁/副总裁等）':
            case '事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）':
            case '人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）':
            case '财务部（总监岗及以上）':
            case '客服部/市场部（总监岗及以上）':
            case '业务部（总监岗及以上）':
            case '其他未列明部门（总监岗及以上）':
              this.$set(item, "flag2", 5);
              break;
          }
        }
        for (let item of this.work_dutyList) {
          if (this.registerForm.work_duty.includes(item.name)) {
            if (this.registerForm.work_age >= item.flag2) {
              this.flag = true;
            }
          }
        }
        console.log("flag", this.flag);
      } else if (
          this.course.filter((item) => item.id == this.registerForm.course_id)[0]
              .name == "国际薪税师二级（中级）"
      ) {
        switch (this.registerForm.hig_edu) {
          case "研究生及以上":
            this.flag =
                this.registerForm.work_age >= 0 ? true : false;
            break;
          case "研究生及以上（在读）":
            this.flag =
                this.registerForm.work_age >= 0 ? true : false;
            break;
          case "本科":
            this.flag =
                this.registerForm.work_age >= 1 ? true : false;
            break;
          case "本科（在读）":
            this.flag =
                this.registerForm.work_age >= 1 ? true : false;
            break;
          case "专科":
            this.flag =
                this.registerForm.work_age >= 3 ? true : false;
            break;
          case "专科（在读）":
            this.flag =
                this.registerForm.work_age >= 3 ? true : false;
            break;
        }
        for (let item of this.certDisplayOptions) {
          switch (item.id) {
            case 25:
            case 28:
            case 20:
            case 16:
            case 33:
            case 34:
            case 6:
            case 5:
              this.$set(item, "flag", 0);
              break;
            case 4:
            case 9:
            case 32:
            case 24:
            case 29:
            case 30:
            case 21:
            case 22:
            case 17:
            case 18:
            case 10:
            case 11:
              this.$set(item,'flag',1);
              break
          }
        }
        for (let item of this.certDisplayOptions) {
          if (item.id == this.registerForm.cert) {
            if (this.registerForm.work_age >= item.flag) {
              this.flag = true;
            }
          }
        }
        for (let item of this.work_dutyList) {
          switch (item.name) {
            case '单位负责人/高级管理人员（董事长/总裁/副总裁等）':
            case '事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等':
            case '人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）':
            case '财务部（总监岗及以上）':
            case '客服部/市场部（总监岗及以上）':
            case '业务部（总监岗及以上）':
            case '其他未列明部门（总监岗及以上）':
              this.$set(item, "flag2", 0);
              break;
            case '人力资源部（薪酬经理岗/薪税服务经理岗）':
            case '财务部（经理岗）':
            case '客服部/市场部（经理岗）':
            case '业务部（经理岗）':
            case '其他未列明部门（经理岗）':
              this.$set(item, "flag2", 1);
              break;
            case '人力资源部（薪酬专员岗/薪税服务专员岗）':
            case '财务部（专员岗）':
            case '客服部/市场部（专员岗）':
            case '业务部（专员岗）':
            case '其他未列明部门（专员岗）':
              this.$set(item, "flag2", 3);
              break;
          }
        }
        for (let item of this.work_dutyList) {
          if (this.registerForm.work_duty.includes(item.name)) {
            if (this.registerForm.work_age >= item.flag2) {
              this.flag = true;
            }
          }
        }
        console.log("flag", this.flag);
      } else if (
          this.course.filter((item) => item.id == this.registerForm.course_id)[0]
              .name == "国际薪税师三级（初级）"
      ) {
        this.flag = true;
        // switch (this.registerForm.hig_edu) {
        //   case "研究生及以上":
        //     this.flag = true
        //     break;
        //   case "研究生及以上（在读）":
        //     this.flag = true
        //     break;
        //   case "本科":
        //     this.flag =
        //         this.DateDiffer(this.registerForm.grad_time) < 1 ? true : false;
        //     break;
        //   case "本科（在读）":
        //     this.flag =
        //         this.DateDiffer(this.registerForm.grad_time) < 1 ? true : false;
        //     break;
        //   case "专科":
        //     this.flag =
        //         this.DateDiffer(this.registerForm.grad_time) < 3 ? true : false;
        //     break;
        //   case "专科（在读）":
        //     this.flag =
        //         this.DateDiffer(this.registerForm.grad_time) < 3 ? true : false;
        //     break;
        //   case "其他":
        //     this.flag = true
        //     break;
        //   case "其他（在读）":
        //     this.flag = true
        //     break;
        // }
        // for (let item of this.work_dutyList) {
        //   switch (item.name) {
        //     case '单位负责人/高级管理人员（董事长/总裁/副总裁等）':
        //     case '事务所负责人/高级管理人员（董事长/权益合伙人/授薪合伙人等）':
        //     case '人力资源部（薪酬总监岗及以上/薪税服务总监岗及以上）':
        //     case '财务部（总监岗及以上）':
        //     case '客服部/市场部（总监岗及以上）':
        //       this.$set(item, "flag2", 1);
        //       break;
        //     case '人力资源部（薪酬专员岗/薪税服务专员岗）':
        //     case '财务部（专员岗）':
        //     case '客服部/市场部（专员岗）':
        //     case '业务部（专员岗）':
        //     case '其他未列明部门（专员岗）':
        //       this.$set(item, "flag2", 3);
        //       break;
        //   }
        // }
        // for (let item of this.work_dutyList) {
        //   if (item.name == this.registerForm.work_duty) {
        //     if (this.registerForm.work_age >= item.flag2) {
        //       this.flag = true;
        //     }
        //   }
        // }
      }
    },
  },
  computed: {
    course_name() {
      if (this.registerForm.course_id !== "") {
        let course_name = "";
        for (let item of this.courseList) {
          if (item.id == this.registerForm.course_id) {
            console.log(item);
            this.exam_cityOptions = item.examdate;
            course_name = item.name;
          }
        }
        return course_name;
      }
      return "";
    },
  },
  components: {
    TencentCaptcha,
  },
};
</script>

<style>
.registerFormDiv .el-form-item__label {
  padding: 0px !important;
}
</style>
<style scoped>
.registerFormDiv .el-form-item {
  margin-bottom: 10px;
}
.registerFormDiv {
  margin-bottom: 100px;
  display: flex;
  justify-content: center;
}
.inputWidth {
  width: 160px;
  margin-right: 20px;
}
.box-card {
  width: auto;
}

.user-register {
  width: 1200px;
  margin: 0 auto;
}
</style>
